package main

import (
	"encoding/json"
	"fmt"
)

type JsonStr struct {
	Name string `json:"name"`
	Age int `json:"age"`
	Info string `json:"info"`
}

func main() {
	stu := JsonStr{"xiaoming", 21, "student"}
	str, err := json.Marshal(stu)
	if err != nil {
		panic(err)
	}
	fmt.Printf("%v\n", string(str))

	stu2 := make(map[string]string)
	stu2["a"] = "a"
	stu2["b"] = "b"
	stu2["c"] = "c"
	stu2["d"] = "d"
	str2, err2 := json.Marshal(stu2)
	if err2 != nil {
		panic(err2)
	}
	fmt.Printf("%v\n", string(str2))

	var temp JsonStr
	err3 := json.Unmarshal([]byte(str), &temp)
	if err3 != nil {
		panic(err3)
	}
	fmt.Printf("%+v\n", temp)
}
